from rest_framework import serializers
from goods.models import GoodsChannel, GoodsCategory, GoodsChannelGroup


class ChannelTypesSerializer(serializers.ModelSerializer):
    # 商品频道组
    class Meta:
        model = GoodsChannelGroup
        fields = ('id', 'name')


class GoodsCategoriesSerializer(serializers.ModelSerializer):
    # 一级分类
    class Meta:
        model = GoodsCategory
        fields = ('id', 'name')


class GoodsChannelSerializer(serializers.ModelSerializer):
    category = serializers.StringRelatedField(label='一级分类名称')
    group = serializers.StringRelatedField(label='频道组名')
    category_id = serializers.IntegerField(label='一级分类名称id')
    group_id = serializers.IntegerField(label='频道组名id')

    class Meta:
        model = GoodsChannel
        fields = ('id', 'category', 'category_id', 'group', 'group_id', 'sequence', 'url')
